import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

// 自动把modules目录下面的js文件模块导入到当前的moduls配置中
const moduleFn = require.context('./modules', false, /\.js$/i)
const modules = moduleFn.keys().reduce((prev, curr) => {
  let value = moduleFn(curr).default
  value = {
    ...value,
    namespaced: true
  }
  let key = /\.\/(\w+)\.js$/.exec(curr)[1]
  prev[key] = value
  return prev
}, {})


Vue.use(Vuex)

export default new Vuex.Store({
  state: {},
  getters,
  modules
})